//
//  NSArray+JSBlock.m
//  CarService
//
//  Created by sixarm on 2018/4/16.
//  Copyright © 2018年 sixarm. All rights reserved.
//

#import "NSArray+JSBlock.h"

@implementation NSArray (JSBlock)


/** 遍历数组 index 和 object */
- (NSArray *)wj_arrayWithIndexMapBlock:(id (^)(NSUInteger index, id object))block{
    
    NSMutableArray *array = [NSMutableArray array];
    [self enumerateObjectsUsingBlock:^(id objects, NSUInteger idx, BOOL *stop) {
        id object = block(idx, objects);
        if (object) {
            [array addObject:object];
        }
    }];
    return array;
}

/** 数组过滤器 */
- (NSArray *)wj_filterBlock:(BOOL (^)(id object))block{
    return [self filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
        return block(evaluatedObject);
    }]];
}

/** 数组剔除器 */
- (NSArray *)wj_reversePickWithArray:(NSArray *)array{
    
    NSMutableArray *results = [NSMutableArray arrayWithArray:self];
    
    for (id obj in array) {
        if ([self containsObject:obj]) { // 包含就剔除
            [results removeObject:obj];
        }
    }
    return results;
}

@end
